package com.kdtech.analyse.Bbs;
import com.kdtech.crawler.at.UrlArgumentTop;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.DoMainUtils;
import com.kdtech.utils.HtmlCleaner;
import com.kdtech.utils.NumberUtils;
import com.kdtech.utils.StringUtils;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.analyse.AnalyseNews;
import com.kdtech.analyse.JSoupUtils;
import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
/**
 * 易读网
 * @author axi
 *
 */
public class DengzhuoBbsAnalyse implements AnalyseNews {

	
	public boolean isDetailPage(String url) {
		boolean bRet = false;
		String[] regex = {
				"http://www.dengzhuo.net/threads/ty-.*-[0-9]*.html",
				"http://www.dengzhuo.net/threads/mop-[0-9]*-[0-9]*.html",
				"http://www.dengzhuo.net/article.php\\?aid=[0-9]*&cid=[0-9]*&lz=[0-9]*&type=mop"
				};
		for (int i = 0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				bRet = true;
				break;
			}
		}
		return bRet;
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {
		String url = urlMeta.getUrl();
		/**
		 * 判断是否为详细页，不是详细页面直接返回空
		 */
		if(!isDetailPage(url)){
		}
		String htmltxt = urlMeta.getHtml();
		Document doc = Jsoup.parse(htmltxt);
		NewsMeta bbs = new NewsMeta();
		String title = "";
		String content = "";
		Long date = null;
		Integer commentNum = 0;
		Integer clickNum = 0;

		/**
		 * 标题
		 */
		title = doc.select("div.lib_Menubox").text();
		/**
		 * 时间
		 */
		date = DateUtils.matchDate(doc.select("div.author").text());
		/**
		 * 内容
		 */
		content = HtmlCleaner.getContentHtml(url,  doc.select("div#content"));
		/**
		 * 初始化、截取 、设置作者信息*******************************************
		 *
		 * */
		String author = null;
		author = JSoupUtils.matchAuthor(doc, "作者:");
		bbs.setAuthor(author);
		/**
		 *                        	 **************************end *************************
		 *
		 **/

		bbs.setUrl(url);
		bbs.setTitle(title);
		bbs.setContent(content);
		bbs.setDate(date);
		bbs.setClickNum(clickNum);
		bbs.setCommentNum(commentNum);
		bbs.setType(4);
		return bbs;
	}

	
	public NewsMeta Update(NewsMeta meta) {
		return null;
	}

	/**
	 * @param args
	 */
	

	
}
